import '../entity/product.dart';
import 'database_helper.dart';

class ProductRepository {
  final dbHelper = DatabaseHelper.instance;

  //插入新产品
  Future<void> insert(Product product) async {
    final db = await dbHelper.database;
    await db.insert('products', product.toMap());
  }

  //根据游戏ID获取所有产品
  Future<List<Product>> getProductsByGameId(String gameId) async {
    final db = await dbHelper.database;
    final maps = await db.query('products', where: 'gameId = ?', whereArgs: [gameId]);
    return List.generate(maps.length, (i) => Product.fromMap(maps[i]));
  }
}